<?php 
	//主函数： 根据起始id，终止id 和 ymd 这几个值来处理珍爱业务，包括抓取、提取和入库
	function chinaz_post($account,$password, $title, $body){
		$url = "my.chinaz.com/login.html";
		$opt_arr = array(
				CURLOPT_REFERER => "http://bbs.chinaz.com",  //referer	
		);
		$preLoginData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/chinaz_portal_cookie.txt",
					"",
					$opt_arr
		);
		preg_match('/name="__PROCESSINPUTVIEWSTATE" value="(.*?)"/', $preLoginData,$match);
		$token = $match[1];
		$parameter = array(	"__PROCESSINPUTVIEWSTATE"=>$token, 
							"logintype"=>'username', 
							"username"=>$account,
							"password"=>$password, 
							"autologin"=>'autologin',
							"returnurl"=>'http://bbs.chinaz.com/Club/list-1.html',
							"login"=>'登录',
							);
		$opt_arr = array(
				CURLOPT_REFERER => "http://my.chinaz.com/login.html",  //referer	
				);
		$page = makeRequest("http://my.chinaz.com/login.html",
					"POST", 
					$parameter, 
					true, 
					ROOT_PATH."/baidu/cookie/chinaz_portal_cookie.txt", 
					ROOT_PATH."/baidu/cookie/chinaz_portal_cookie.txt",
					$opt_arr
					);
		$url = 'http://bbs.chinaz.com/Club/list-1.html';
		$opt_arr = array(
				CURLOPT_REFERER => "http://bbs.chinaz.com",  //referer	
		);
		$preData = makeRequest($url, 
					"GET", 
					"", 
					false, 
					ROOT_PATH."/baidu/cookie/chinaz_portal_cookie.txt",
					ROOT_PATH."/baidu/cookie/chinaz_portal_cookie.txt",
					$opt_arr
		);
		
		preg_match_all('%<tbody class="forumtopics-list">([\s\S]*?)</tbody>%', $preData,$matches);
		preg_match_all('/<td class="title">[\s\S]*?<a href="(.*?)"/',$matches[1][0],$urls);
		foreach($urls[1] as $key=>$url){
			$msg = getOneJoke();
			$post_url = 'http://bbs.chinaz.com'.$url.'?_max_ajaxids_=ap_pager_up,ap_pager_down,ap_threadinfo,ap_postlist,ap_quickreply,ap_quickreplyoption,ap_vcode,ap_error';
			echo $post_url."\n";
			$opt_arr = array(
				CURLOPT_REFERER => "http://bbs.chinaz.com/Club/list-1.html",  //referer	
			);
			$parameter = array(	"__PROCESSINPUTVIEWSTATE"=>$token, 
							"editor"=>$msg, 
							"postPageNumber"=>1,
							"tolastpage"=>1,
							"postButton"=>'',
							);
			var_dump($parameter);
			
			$postpage = makeRequest($post_url,
					"POST", 
					$parameter, 
					false, 
					ROOT_PATH."/baidu/cookie/chinaz_portal_cookie.txt",
					ROOT_PATH."/baidu/cookie/chinaz_portal_cookie.txt",
					$opt_arr
					);
			sleep(50);
		}
	}
	//生成缘来登录后的cookie
	function makeBaiduCookie()
	{
		//step1: browser the mainpage and get jsession id ,dump it to Baidu_portal_cookie.txt	
		makeRequest("http://hi.baidu.com/", 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					"",
					""
					);
		//step2 login with the cookies which is fetched by previous request
		$parameter = array(	"tpl"=>"sp", 
							"tpl_reg"=>'sp', 
							"u"=>'',
							"username"=>"bangshoushen", 
							"password"=>"Smart789852",
							"mem_pass"=>"checked",
							);
		$opt_arr = array(
				CURLOPT_HEADER => 0,  //referer	
				CURLOPT_SSL_VERIFYPEER => 0,  //referer	
				CURLOPT_AUTOREFERER => 1,  //referer	
				CURLOPT_AUTOREFERER => 1,  //referer
				CURLOPT_REFERER => "http://hi.baidu.com/",  //referer	
				);
		$page = makeRequest("https://passport.baidu.com/v2/api/?getapi&class=login&tpl=pp&tangram=false",
					"GET", 
					$parameter, 
					true, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt", 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					""
		);
		return $page;
	}
	//post baidu
	function baidu_post($account,$password,$catname=' 默认分类',$title, $content){
		//baidu login url
		$url = "https://passport.baidu.com/v2/?login";
		$opt_arr = array(
				CURLOPT_REFERER => "https://www.baidu.com/",  //referer	
		);
		$preLoginData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					"",
					$opt_arr
		);
		
		//请求token
		$url = "https://passport.baidu.com/v2/api/?getapi&class=login&tpl=pp&tangram=false";
		$opt_arr = array(
				CURLOPT_REFERER => "https://passport.baidu.com/v2/?login",  //referer	
		);
		
		$preLoginData = makeRequest($url, 
					"GET", 
					"", 
					false, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					$opt_arr
		);
		
		preg_match('/login_token=\'(.*?)\'/',$preLoginData,$syscheckcode);
				
		$parameter = array(	"ppui_logintime"=>14439, 
							"charset"=>'UTF-8', 
							"codestring"=>'',
							"token"=>$syscheckcode[1],
							"isPhone"=>'false',
							"index"=>0,
							"safeflg"=>0,
							"u"=>'',
							"loginType"=>1,
							"tpl"=>'pp',
							"callback"=>'parent.bdPass.api.login._postCallback',
							"verifycode" =>'',
							"staticpage"=>'https://passport.baidu.com/v2Jump.html',
							"username"=>$account, 
							"password"=>$password,
							"mem_pass"=>"on",
							);
	
		$opt_arr = array(
				CURLOPT_REFERER => "https://passport.baidu.com/v2/?login",  //referer	
				);
				
		$loginurl = 'https://passport.baidu.com/v2/api/?login';
		$loginpage = makeRequest($loginurl,
					"POST", 
					$parameter, 
					true, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					$opt_arr
					);
		preg_match('/encodeURI\(\'(.*?)\'/',$loginpage,$urls);
		$url = $urls[1];
		
		$opt_arr = array(
				CURLOPT_REFERER => "https://passport.baidu.com/v2/api/?login",  //referer	
		);
		
		$preData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					$opt_arr
		);
		preg_match('/hao123Param=(.*?)$/',$url,$hao);
		$haourl = $hao[1];
		list($usec, $sec) = explode(" ", microtime());
		$randstr = $usec.$sec;
		$url = 'https://user.hao123.com/static/crossdomain.php?bdu='.$haourl.'&t='.$randstr;
		$opt_arr = array(
				CURLOPT_REFERER => "https://passport.baidu.com/v2/?login",  //referer	
		);
		$preData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					$opt_arr
		);
		
		//自动发送文章
		$url = "http://hi.baidu.com/pub/show/createtext";
		$opt_arr = array(
				CURLOPT_REFERER => "http://hi.baidu.com/home",  //referer	
		);
		
		$preData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					$opt_arr
		);
		
		preg_match('/window.qBdsToken="(.*?)"/',$preData,$token);
		$postvalue = array(
				  'title'          => $title,
				  'content'        => $content,
				  'private'           => 0,
				  'imgnum'      => 0,
				  'bdstoken'      => $token[1],
				  'qbid'      => '',
				  'refer'      => 'http://hi.baidu.com/home/',
				  'multimedia[]'      => '',
				  'private1'      => 0,
				  'qing_request_source'      => ''
				  );
		
		$opt_arr = array(
				CURLOPT_REFERER => "http://hi.baidu.com/pub/show/createtext",  //referer	
				);
				
		$url = 'http://hi.baidu.com/pub/submit/createtext';
		$page = makeRequest($url,
					"POST", 
					$postvalue, 
					false, 
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					ROOT_PATH."/baidu/cookie/baidu_portal_cookie.txt",
					""
					);
		var_dump($page);//string(46) "{"errorNo" : "0","errorMsg" : "","data": [ ]}"
}
	//create rand number 
	function microtime_int(){
		list($usec, $sec) = explode(" ", microtime());
		return  round((float)($sec.$usec),2)*100;
	}
	//sina post
	function sina_post($username,$password,$catname=1,$title='默认', $content='默认的内容'){
		$preurl = 'http://login.sina.com.cn/sso/prelogin.php?entry=account&callback=sinaSSOController.preloginCallBack';
		$preurl .='&su='.base64_encode(urlencode($username)).'&rsakt=mod&client=ssologin.js(v1.4.2)&_='.microtime_int();
		
		$opt_arr = array(
				CURLOPT_REFERER => "http://login.sina.com.cn/",  //referer	
		);
		$preLoginData = makeRequest($preurl, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sina_portal_cookie.txt",
					"",
					$opt_arr
					);
		
		preg_match('/sinaSSOController.preloginCallBack\((.*)\)/',$preLoginData,$preArr);
		
		$jsonArr = json_decode($preArr[1],true);
		include('rsa.php');
		include('BigInteger.php');
		$public = 65537;
		$modulus = $jsonArr['pubkey'];
		$keylength = 1024;
		$modulus_16 = new Math_BigInteger($modulus,16);
		$mend = $modulus_16->toString();

		$message = $jsonArr['servertime']."\t".$jsonArr['nonce']."\n".$password;
		$encrypted = rsa_encrypt($message, $public, $mend, $keylength);
		$sp = bin2hex($encrypted); //这里也可以用Base64，QQ就是Base64
		$postvalues = array(
				  'entry'          => 'account',
				  'gateway'        => 1,
				  'from'           => '',
				  'savestate'      => 0,
				  'useticket'      => 0,
				  'vsnf'      	   => 1,
				  'su'             => base64_encode(urlencode($username)),
				  'service'        => 'sso',
				  'servertime'     => $jsonArr['servertime'],
				  'nonce'          => $jsonArr['nonce'],
				  'pwencode'       => 'rsa2',
				  'rsakv'          => $jsonArr['rsakv'],
				  'sp'			=> $jsonArr['pubkey'],
				  //'sp'             => sha1(sha1(sha1($password)).$jsonArr['servertime'].$jsonArr['nonce']),
				  'sp'             => $sp,
				  'encoding'       => 'UTF-8',
				  'prelt'       => 90,
				  'callback'       => 'parent.sinaSSOController.loginCallBack',
				  'returntype'     => 'IFRAME',
				  'setdomain'     => 1
			  );
		
		$url = 'https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.2)';
		$opt_arr = array(
				CURLOPT_REFERER => "http://login.sina.com.cn/",  //referer	
		);
		$loginData = makeRequest($url, 
					"POST", 
					$postvalues, 
					true, 
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					ROOT_PATH."/baidu/cookie/sina_portal_cookie.txt",
					""
					);
		preg_match('/location.replace\("(.*?)"/',$loginData,$urls);
				
		$opt_arr = array(
				CURLOPT_REFERER => "http://login.sina.com.cn/",  //referer	
		);
		$preLoginData = makeRequest($urls[1], 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					$opt_arr
					);
		
		preg_match('/parent.sinaSSOController.setCrossDomainUrlList\((.*?)\)/',$preLoginData,$preArr1);
		
		$jsonArr1 = json_decode($preArr1[1],true);
		
		$url_weibo = $jsonArr1['arrURL'][0].'&callback=sinaSSOController.doCrossDomainCallBack&scriptId=ssoscript0&client=ssologin.js(v1.4.2)&_='.microtime_int();
		
		$opt_arr = array(
				CURLOPT_REFERER => "http://login.sina.com.cn/",  //referer	
		);
		$preLoginData = makeRequest($url_weibo, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					$opt_arr
					);
		
		$url_kandian = $jsonArr1['arrURL'][1].'&callback=sinaSSOController.doCrossDomainCallBack&scriptId=ssoscript1&client=ssologin.js(v1.4.2)&_='.microtime_int();
		$opt_arr = array(
				CURLOPT_REFERER => "http://login.sina.com.cn/",  //referer	
		);
		$preLoginData = makeRequest($url_kandian, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					$opt_arr
					);
		$url = "http://login.sina.com.cn/";
		$opt_arr = array(
				CURLOPT_REFERER => "http://login.sina.com.cn/",  //referer	
		);
		$preLoginData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					$opt_arr
					);
		$url = 'http://login.sina.com.cn/member/app.php?entry=sso&act=my';
		$opt_arr = array(
				CURLOPT_REFERER => "http://login.sina.com.cn/",  //referer	
		);
		$preLoginData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					$opt_arr
					);
		$url = 'http://login.sina.com.cn/member/my.php?entry=sso';
		$opt_arr = array(
				CURLOPT_REFERER => "http://login.sina.com.cn/",  //referer	
		);
		$preLoginData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					ROOT_PATH."/baidu/cookie/sina_cookie.txt",
					$opt_arr
					);
		
		//自动发送文章

		$opt_arr = array(
				CURLOPT_REFERER => "http://i.blog.sina.com.cn/",  //referer	
		);
		$url = "http://control.blog.sina.com.cn/admin/article/article_add.php";
		$page = makeRequest($url, 
								"GET" , 
								"", 
								true, 
								ROOT_PATH."/baidu/cookie/sina_cookie.txt",
								ROOT_PATH."/baidu/cookie/sina_cookie.txt",
								$opt_arr
								);
		
		$conlen = countStrLength($content);
		preg_match('/id="timestamp".*?value="(.*?)"/',$page,$timestamp);
		preg_match('/name="vtoken".*?value="(.*?)"/',$page,$vtoken);
		
		$postvalues = array(
				  'ptype'          => '',
				  'teams'          => '',
				  'worldcuptags'   => '',
				  'album'        => '',
				  'album_cite'        => '',
				  //'timestamp'      => $timestamp[1],
				  'blog_id'        => '',
				  'is_album'        => 0,
				  'stag'        => '',
				  'sno'        => '',
				  'book_worksid'        => '',
				  'channel_id'        => '',
				  'url'        => '',
				  'channel'        => '',
				  'newsid'        => '',
				  'fromuid'        => '',
				  'wid'        => '',
				  'articletj'        => '',
				  'vtoken'        => $vtoken[1],
				  'is_media'        => 0,
				  'is_stock'        => 0,
				  'is_tpl'        => 0,
				  'assoc_article'        => '',
				  'assoc_style'        => 1,
				  'assoc_article_data'        => '',
				  'article_BGM'        => '',
				  'xRankStatus'        => '',
				  'commentGlobalSwitch'        => '',
				  'commenthideGlobalSwitch'        => '',
				  'articleStatus_preview'        => 1,
				  'source'        => '',
				  'topic_id'        => 0,
				  'topic_channel'        => 0,
				  'topic_more'        => '',
				  'utf8'        => 1,
				  'conlen'        =>  $conlen,
				  'date_pub'        => date('Y-m-d',time()),
				  'blog_title'        => $title,
				  'blog_class'        => $catname,
				  'articleTime'        => date('H:i:s',time()),
				  'blog_body'        => $content,
				  'tag'        => '',
				  'sina_sort_id'        => 117,
				  'join_circle'        => 1,
				  'x_cms_flag'        => 0
				  );
		 // var_dump($postvalues);
		// exit;
		$opt_arr = array(
				CURLOPT_REFERER => "http://control.blog.sina.com.cn/admin/article/article_add.php",  //referer	
				);
		$posturl = 'http://control.blog.sina.com.cn/admin/article/article_post.php';
		$postpage = makeRequest($posturl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/sina_cookie.txt",
								ROOT_PATH."/baidu/cookie/sina_cookie.txt",
								$opt_arr
								);
								
		var_dump($postpage);//string(79) "{"code":"B06001","data":"636edaf50101c7jv","ycon_length":392,"jcon_length":394}"
		
	}
	/**
	* 统计字数
	* @author kim
	* @param string $string
	* @return int
	*/
	function countStrLength($string){
		//将中文(3字符)替换成英文(1字符)然后再统计
	   $string = preg_replace ( '/[\x80-\xff]{3}/', 'x', $string );
	   return strlen ( $string );
	}
	//sohu post
	function sohu_post($username,$password,$catname=1,$title='默认', $content='默认的内容'){
		$url = 'https://passport.sohu.com/web/cardlog.jsp?desc=beginLogin&loginProtocal=https&userid='.$username.'&appid=9998&browserType=7&status=&count=0&max=100&flag=0';
		$opt_arr = array(
				CURLOPT_REFERER => "https://passport.sohu.com/",  //referer	
				);
		$preLoginData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sohu_login_cookie.txt",
					"",
					$opt_arr
					);
		
		$preurl = 'https://passport.sohu.com/sso/login.jsp?userid=';
		$preurl .= urlencode($username).'&password=';
		$preurl .= md5($password).'&appid=9998&persistentcookie=1&s=';
		$preurl .= microtime_int().'&b=7&w=1360&pwdtype=1&v=26&t='.microtime_int();
		
		$opt_arr = array(
				CURLOPT_REFERER => "http://i.sohu.com/login/",  //referer	
				);
		$preLoginData = makeRequest($preurl, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/sohu_login_cookie.txt",
					"",
					$opt_arr
					);
		//自动发文章
		$opt_arr = array(
				CURLOPT_REFERER => "http://blog.sohu.com",  //referer	
				);
		$url = "http://blog.sohu.com/manage/entry.do?m=add&t=index";
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/sohu_login_cookie.txt",
								$opt_arr
								);
		preg_match('/name="aid".*?value="(.*?)"/',$page,$aid);
		$postvalues = array(
				  'oper'          => 'art_ok',
				  'm'          => 'save',
				  'aid'          => $aid[1],
				  'shortcutFlag' => true,
				  'contrChId' => '',
				  'contrCataId' => '',
				  'entrytitle' => $title,
				  'keywords' => '',
				  'categoryId' => 0,
				  'newGategory' => '',
				  'entrycontent' => $content,
				  'excerpt' => '',
				  'allowComment' => 2,
				  'perm' => 0,
				  );
		$opt_arr = array(
				CURLOPT_REFERER => "http://blog.sohu.com/manage/entry.do?m=add&t=shortcut",  //referer	
				);
				
		$posturl = 'http://blog.sohu.com/manage/entry.do';
		$postpage = makeRequest($posturl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/sohu_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/sohu_login_cookie.txt",
								$opt_arr
								);
		//printlog("success!! : $postpage", "sohu_post");
		var_dump($postpage);
	}
	//HTML实体的转换
	function htmlentities_decode($text){
		$arr = explode('&#',$text);
		$newtext = '';
		foreach($arr as $key=>$value){
			$newtext .=chr($value);
		}
		return $newtext;
	}
	//cmt 的后缀 
	function cmt_subfix(){
		$str = rand(1000000000,9999999999);
		$str = strrev($str);
		return $str;
		
	}
	//163 post
	function net163_post($username,$account,$password,$catname=1,$title='默认', $content='默认的内容'){
		$preurl = 'https://reg.163.com/logins.jsp';
		$opt_arr = array(
				CURLOPT_REFERER => "https://reg.163.com/logins.jsp",  //referer	
				);
		$preLoginData = makeRequest($preurl, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/net_portal_cookie.txt",
					"",
					$opt_arr
					);
		preg_match('/name=syscheckcode.*?value="(.*?)"/',$preLoginData,$syscheckcode);
		$postvalues = array(
				  'url'          => '',
				  'product'      => '',
				  'savelogin'    => '',
				  'outfoxer'     => '',
				  'domains'      => '',
				  'syscheckcode' => $syscheckcode[1],
				  'username'          => $username,
				  'password'          => $password,
				  );
		// var_dump($postvalues );
		
		$loginurl = 'https://reg.163.com/logins.jsp';
		$postpage = makeRequest($loginurl, 
								"POST" , 
								$postvalues, 
								true, 
								ROOT_PATH."/baidu/cookie/net_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/net_portal_cookie.txt",
								$opt_arr
								);
		
		$url = "http://{$account}.blog.163.com/blog/getBlog.do?fromString=blogmodule";
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/net_login_cookie.txt",
								""
								);
								
		$opt_arr = array(
				CURLOPT_REFERER => "http://api.blog.163.com/crossdomain.html?t=20100205",  //referer	
				);
		preg_match("/b:2,.*?id:'(.*?)'/",$page,$cls);
		preg_match('/NETEASE_BLOG_TOKEN_EDITBLOG".*?"(.*?)"/',$page,$token);
		$postvalues = array(
				  'tag'        => '',
				  'cls'          => $cls[1],
				  'allowview'   => -100,
				  'refurl'   => '',
				  'abstract'   => '',
				  'bid'   => '',
				  'origClassId'   => '',
				  'origPublishState'   => '',
				  'oldtitle'   => '',
				  'todayPublishedCount'   => 4,
				  'NETEASE_BLOG_TOKEN_EDITBLOG'   => $token[1],
				  'title'   => $title,
				  'HEContent'   => $content,
				  'copyPhotos'   => '',
				  'suggestedSortedIds'   => '',
				  'suggestedRecomCnt'   => '',
				  'suggestedStyle'   => 0,
				  'isSuggestedEachOther'   => 0,
				  'photoBookImgUrl'   => '',
				  'msyn'   => 1,
				  'miniBlogCard'   => 0,
				  'p'   => 1,
				  );
				  
		$posturl ="http://api.blog.163.com/{$account}/editBlogNew.do?p=1&n=1&from=blogmodule";
		$post = makeRequest($posturl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/net_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/net_login_cookie.txt",
								$opt_arr
								);
		var_dump($post);//string(120) "{r:1,id:'fks_087065084080081067081086087075072084081071093086086066085084',sfx:'blog/static/2049001122012101310342812/'}"	
	}
	//babytree post
	function babytree_post($username,$password,$catname=1,$title='默认', $content='默认的内容',$tag=''){
		$preurl = "http://www.babytree.com/reg/login.php";
		$opt_arr = array(
			CURLOPT_REFERER => "http://www.babytree.com",  //referer	
		);
		$preLoginData = makeRequest($preurl, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/babytree_portal_cookie.txt",
					"",
					$opt_arr
					);
		preg_match('/crumb".*?"(.*?)"/',$preLoginData,$crumb);
		$postvalues = array(
				  'email'          => $username,
				  'password'          => $password,
				  'p'          => 1,
				  'crumb'          => $crumb[1],
				  'action'          => 'login'
				  );
		//var_dump($postvalues);
		
		$loginurl = 'http://www.babytree.com/common/reg.ajax.php';
		$opt_arr = array(
			CURLOPT_REFERER => "http://www.babytree.com/reg/login.php",  //referer	
		);
		$postpage = makeRequest($loginurl, 
								"POST" , 
								$postvalues, 
								true, 
								ROOT_PATH."/baidu/cookie/babytree_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/babytree_portal_cookie.txt",
								$opt_arr
								);
		
		//var_dump($postpage);
		if (preg_match('/success/i', $postpage)) {
			$indexurl = "http://www.babytree.com/newsfeed/";
			$opt_arr = array(
				CURLOPT_REFERER => "http://www.babytree.com/reg/login.php",  //referer	
			);
			$indexData = makeRequest($indexurl, 
					"GET", 
					"", 
					false, 
					ROOT_PATH."/baidu/cookie/babytree_login_cookie.txt",
					ROOT_PATH."/baidu/cookie/babytree_login_cookie.txt",
					$opt_arr
			);
			//var_dump($indexData);
			preg_match('/showuser.php\?uid=(.*?)&tab=game/',$indexData,$uid);
			echo $uid[1];
			$opt_arr = array(
				CURLOPT_REFERER => "http://www.babytree.com/user/showuser.php?uid=".$uid[1]."&tab=journal",  //referer	
			);
			$posturl ="http://www.babytree.com/user/showuser.php?uid=".$uid[1]."&tab=journal&view=new";
			$postData = makeRequest($posturl, 
					"GET", 
					"", 
					false, 
					ROOT_PATH."/baidu/cookie/babytree_login_cookie.txt",
					ROOT_PATH."/baidu/cookie/babytree_login_cookie.txt",
					$opt_arr
			);
			
			//var_dump($postData);
			preg_match('/id="crumb".*?"(.*?)"/',$postData,$crumb);
			$postvalues = array(
				  'uid'          => $uid[1],
				  'tab'          => 'journal',
				  'view'          => 'new',
				  'action'          => 'create',
				  'crumb'          => $crumb[1],
				  'random'          => '',
				  'title'          => $title,
				  'date'          => date('Y-m-d',time()),
				  'category'          => 12490349,
				  'catName'          => '',
				  'content'          => $content,
				  'letterid'          => 0,
				  'tags'          => $tag,
				  'overall'          => 'open',
				  'target_id'          => 120,
				  'yuerjing'          => 28
			);
			//var_dump($postvalues);
			$opt_arr = array(
				CURLOPT_REFERER => "http://www.babytree.com/user/showuser.php?uid=".$uid[1]."&tab=journal&view=new",  //referer	
			);
			$finalurl = "http://www.babytree.com/user/showuser.php";
			$submitpage = makeRequest($finalurl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/babytree_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/babytree_login_cookie.txt",
								$opt_arr
								);
			var_dump($submitpage);
			//string(77) "<script>parent.handleJournalError({"status":"ok","jid":"11175388"});</script>"
			exit;
		} else {
			echo 'login error';
			exit;
		}
	}
	//blogbus post
	function blogbus_post($username,$password,$catname=1,$title='默认', $content='默认的内容'){
		$opt_arr = array(
			CURLOPT_REFERER => "http://passport.blogbus.com/login_form",  //referer	
		);
		$postvalues = array(
				  'username'          => $username,
				  'password'          => $password,
				  'remember'          => 1
				  );
		//var_dump($postvalues);
		
		$loginurl = 'http://passport.blogbus.com/login';
		$postpage = makeRequest($loginurl, 
								"POST" , 
								$postvalues, 
								true, 
								ROOT_PATH."/baidu/cookie/blogbus_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/blogbus_login_cookie.txt",
								$opt_arr
								);
		
		//自动发文章
		$url = "http://blog.home.blogbus.com/posts/form";
		$opt_arr = array(
			CURLOPT_REFERER => "http://www.blogbus.com/user/",  //referer	
		);
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/blogbus_login_cookie.txt",
								$opt_arr
								);
		
		$opt_arr = array(
			CURLOPT_REFERER => "http://blog.home.blogbus.com/posts/form",  //referer	
		);
		preg_match('/action="(.*?)".*?name="EditorForm"/',$page,$postaddress);
		preg_match('/name="post_time".*?value="(.*?)"/',$page,$posttime);
		
		$postvalues = array(
				  'title'   => $title,
				  'post_time'   => $posttime[1],
				  'content'   => $content,
				  'sort_id'   => '',
				  'tags'   => '',
				  'excerpt'   => '',
				  'visibility'   => 'public',
				  'password'   => '',
				  'visi_opt'   => 'public',
				  'allow_comment'   => 1,
				  'allow_trackback'   => 1,
				  'allow_auto_link'   => 1,
				  'force'   => 0,
				  );
		//var_dump($postvalues );		
		$posturl = "http://blog.home.blogbus.com".$postaddress[1];
		
		$post = makeRequest($posturl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/blogbus_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/blogbus_login_cookie.txt",
								$opt_arr
								);
		var_dump($post);//string(94) "{"success":{"blog_id":6490246,"current_module":"posts","current_method":"posts","request":{}}}"
	}
	
	// hexun post
	function hexun_post($username,$password,$catname=1,$title='默认', $content='默认的内容'){
		$opt_arr = array(
			CURLOPT_REFERER => "http://i.hexun.com/default.html",  //referer	
		);
		$url = 'http://i.hexun.com/default.html';
		$preLoginData = makeRequest($url, 
					"GET", 
					"", 
					true, 
					ROOT_PATH."/baidu/cookie/hexun_login_cookie.txt",
					"",
					$opt_arr
					);
		
		$postvalues = array(
				  'username'          => $username,
				  'password'          => $password,
				  'LoginStateAuto'          => 1,
				  'LoginStateName'          => 1,
				  'gourl'          => ''
				  );
		
		$loginurl = 'https://reg.hexun.com/login.aspx';
		$postpage = makeRequest($loginurl, 
								"POST" , 
								$postvalues, 
								true, 
								ROOT_PATH."/baidu/cookie/hexun_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/hexun_login_cookie.txt",
								$opt_arr
								);
		//自动发文章
		$url = "http://post.blog.hexun.com/i/newpost.aspx";
		$opt_arr = array(
			CURLOPT_REFERER => "http://i.hexun.com/myhome.html",  //referer	
		);
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/hexun_login_cookie.txt",
								$opt_arr
								);
		
		preg_match('%http://i\.hexun\.com/myhome\.html\?id=(\d+)%i',$page,$uid);
		
		$url = "http://post.blog.hexun.com/".$uid[1]."/postarticle.aspx";
		$opt_arr = array(
			CURLOPT_REFERER => "http://i.hexun.com/myhome.html",  //referer	
		);
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/hexun_login_cookie.txt",
								$opt_arr
								);
		$opt_arr = array(
			CURLOPT_REFERER => $url,  //referer	
		);
		$postvalues = array(
				  'blogname'   => $uid[1],
				  'action'   => 0,
				  'oldclass'   => 0,
				  'weibo'   => 1,
				  'newcategorytextbox'   => '请输入新分类名称',
				  'chkselected'   => '',
				  'categorylist'   => 0,
				  'ContentSpaw'   => $content,
				  'TitleTextbox'   => $title,
				  'articleid'   => 0,
				  'draftid'   => 0,
				  'SourceTextbox'   => '',
				  'SourceUrlTextbox'   => '',
				  'TagTextbox'   => '美食',
				  'TrackbackTextbox'   => '',
				  'BriefTextbox'   => '',
				  'VerificationInput'   =>'undefined',
				  'postid'   => 0,
				  'HideCheckbox'   => 1,
				  'AcceptCommentCheckbox'   => 1,
				  'posttype'   => '原创',
				  'postclass'   => 80,
				  'StickOutCheckbox'   => 0,
				  'StickOutOrderNumberTextbox'   => 0,
				  'StickOutExpiredTimeTextbox'   => '',
				  'xfh'   => 'undefined',
				  '_'   => '',
				  );
		//var_dump($postvalues );		
		$posturl = "http://post.blog.hexun.com/PostArticleHandler.ashx";
		
		$post = makeRequest($posturl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/hexun_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/hexun_login_cookie.txt",
								$opt_arr
								);
		var_dump($post);//string(72) "Success|操作成功|http://19603748.blog.hexun.com/81158326_d.html|81158326"
	}
	// diandian post
	function diandian_post($username,$password,$catname=1,$title='默认', $content='默认的内容'){
		$opt_arr = array(
			CURLOPT_REFERER => "http://www.diandian.com/login",  //referer	
		);
		
		$postvalues = array(
				  'account'          => $username,
				  'password'          => $password,
				  'nextUrl'          => '',
				  'lcallback'          => '',
				  'persistent'          => 1
				  );
		$url = 'http://www.diandian.com/login';
		$postpage = makeRequest($url, 
								"POST" , 
								$postvalues, 
								true, 
								ROOT_PATH."/baidu/cookie/diandian_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/diandian_login_cookie.txt",
								$opt_arr
								);
		// printlog("success!!: $postpage", "diandian");
		// var_dump($postpage);
		//自动发文章
		$url = "http://www.diandian.com/home";
		$opt_arr = array(
			CURLOPT_REFERER => "http://www.diandian.com/login",  //referer	
		);
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/diandian_login_cookie.txt",
								$opt_arr
								);
		
		preg_match('/class="text" href="(.*?)">/i',$page,$text);
				
		$url =$text[1];
		$opt_arr = array(
			CURLOPT_REFERER => "http://www.diandian.com/home",  //referer	
		);
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/diandian_login_cookie.txt",
								$opt_arr
								);
		// printlog("success!!: $page", "diandian");
		preg_match('/DDformKey.*?=.*?\'(.*?)\'/i',$page,$key);
		preg_match('/ENV.blogUrl.*?=.*?\'(.*?)\'/i',$page,$user);
		// var_dump($user);
		// exit;
		$opt_arr = array(
			CURLOPT_REFERER => $url,  //referer	
		);
		$postvalues = array(
				  'formKey'   => $key[1],
				  'title'   => $title,
				  'content'   => $content,
				  'uri'   => '',
				  'tags'   => '',
				  'privacy'   => 0,
				  'setTop'   => 'false',
				  'creativeCommonsEnable'   => 'false',
				  'creativeCommonsType'   => 'by_nc_nd',
				  'syncToWeibo'   =>'false',
				  'syncToQqWeibo'   =>'false',
				  'syncToDouban'   =>'false',
				  'syncToQzone'   =>'false',
				  'syncToRenren'   =>'false',
				  'syncToFacebook'   =>'false',
				  'syncToTwitter'   =>'false',
				  'syncToFlickr'   =>'false',
				  'type'   => 'text',
				  'blogUrl'   => $user[1],
				  'autoSaveId'   => 0,
				  'autoSaveType'   => 0,
				  );
		// var_dump($postvalues );		
		// exit;
		$posturl = "http://www.diandian.com/autosave/save";
		
		$post = makeRequest($posturl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/diandian_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/diandian_login_cookie.txt",
								$opt_arr
								);
		// var_dump($post);//string(62) "{"result":"保存成功！","autoSaveId":5919366,"errCode":0} "
		// exit;
		$jsonArr = json_decode($post,true);
		$opt_arr = array(
			CURLOPT_REFERER => $url,  //referer	
		);
		$postvalues = array(
				  'formKey'   => $key[1],
				  'title'   => $title,
				  'content'   => $content,
				  'uri'   => '',
				  'tags'   => '',
				  'privacy'   => 0,
				  'setTop'   => 'false',
				  'creativeCommonsEnable'   => 'false',
				  'creativeCommonsType'   => 'by_nc_nd',
				  'syncToWeibo'   =>'false',
				  'syncToQqWeibo'   =>'false',
				  'syncToDouban'   =>'false',
				  'syncToQzone'   =>'false',
				  'syncToRenren'   =>'false',
				  'syncToFacebook'   =>'false',
				  'syncToTwitter'   =>'false',
				  'syncToFlickr'   =>'false',
				  'type'   => 'text',
				  'blogUrl'   => $user[1],
				  'autoSaveId'   => $jsonArr['autoSaveId'],
				  'autoSaveType'   => 0,
				  
				  );
		// var_dump($postvalues );
		// exit;
		$posturl = 'http://www.diandian.com/dianlog/'.$user[1].'/new/text';
		//echo $posturl;
		
		$post = makeRequest($posturl, 
							"POST" , 
							$postvalues, 
							false, 
							ROOT_PATH."/baidu/cookie/diandian_login_cookie.txt",
							ROOT_PATH."/baidu/cookie/diandian_login_cookie.txt",
							$opt_arr
							);
		var_dump($post);//string(107) "{"result":"发布成功","errCode":"0","publisherAfterTipsPortlet":"4e73d2e0-2d60-11e2-8bff-782bcb383994"} "
	}
	// yaolan post
	function yaolan_post($username,$password,$catname=1,$title='默认', $content='默认的内容'){
		$opt_arr = array(
			CURLOPT_REFERER => "http://user.yaolan.com/Login.aspx",  //referer	
		);
		$url = "http://user.yaolan.com/Login.aspx";
		$page = makeRequest($url, 
								"GET" , 
								"", 
								true, 
								ROOT_PATH."/baidu/cookie/yaolan_login_cookie.txt",
								'',
								$opt_arr
								);
		preg_match('/id="__VIEWSTATE".*?value="(.*?)"/i',$page,$state);
		preg_match('/id="__EVENTVALIDATION".*?value="(.*?)"/i',$page,$event);
		
		$sed =substr(md5($password),8,16);
		$pass = unicode_md5($username.$sed);
		
		$postvalues = array(
				  '__EVENTTARGET'          => 'btnLogin',
				  '__EVENTARGUMENT'          => '',
				  '__VIEWSTATE'          => $state[1],
				  '__EVENTVALIDATION'          => $event[1],
				  'txtUserName'          => $username,
				  'txtPassword'          => $pass,
				  'chkRemember'          => 'yes',
				  );
		$url = 'http://user.yaolan.com/Login.aspx';
		$postpage = makeRequest($url, 
								"POST" , 
								$postvalues, 
								true, 
								ROOT_PATH."/baidu/cookie/yaolan_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/yaolan_login_cookie.txt",
								$opt_arr
								);
		//自动发文章
		$url = "http://space.yaolan.com/blog/write/";
		$opt_arr = array(
			CURLOPT_REFERER => "http://space.yaolan.com",  //referer	
		);
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/yaolan_login_cookie.txt",
								$opt_arr
								);
		
		
		//获取相关cookie
		$file = file_get_contents(ROOT_PATH."/baidu/cookie/yaolan_login_cookie.txt");
		preg_match('/user_id\s*(.*?)\s/i',$file,$uid);
		preg_match('/user_name\s*(.*?)\s/i',$file,$username);
				
		
		$opt_arr = array(
			CURLOPT_REFERER => "http://space.yaolan.com/blog/write/",  //referer	
		);
		
		$postvalues = array(
				  'title'   => $title,
				  'content'   => $content,
				  'date'   => date('Y-m-d',time()),
				  'diarytype'   => '-1',
				  'selview'   => 1,
				  'chkforediter'   => 'false',
				  'commendTypeId'   => 1,
				  'topicId'   => 0,
				  'chkNoAllowReplie'   =>'false',
				  'userid'   => $uid[1],
				  'username'   =>$username[1],
				  'resid'   =>'',
				  'letterid'   =>0,
				  'AtFriendNames'   =>'',
				  'ActiveType'   =>0,
				  'chkSendToBBs'   =>'undefined',
				  'BBsBoardId'   =>'undefined'
				  );
		
		$posturl = 'http://space.yaolan.com/mydiary/uc/writediary.ashx';
		$post = makeRequest($posturl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/yaolan_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/yaolan_login_cookie.txt",
								$opt_arr
								);
		var_dump($post);//string(93) "{"IsSuccess":"true","Message":"日记发表成功！","UserId":"52419439","ResId":"20830203"}"
	}
	//摇篮网专用
	function unicode_md5($str)
	{
		$str = iconv('UTF-8', 'UTF-16LE', $str);
		$str = md5($str);
		return $str;
	}
	
	// tianya post
	function tianya_post($username,$password,$catname=1,$title='默认', $content='默认的内容'){
		$opt_arr = array(
			CURLOPT_REFERER => "http://www.tianya.cn",  //referer	
		);
				
		$postvalues = array(
				  'method'          => 'name',
				  'vwriter'          => $username,
				  'vpassword'          => $password,
				  'rmflag'          => 1,
				  'fowardURL'          => 'http://www.tianya.cn',
				  'returnURL'          => '',
				  'from'          => '',
				  'Submit'          => '登陆',
				  );
		$url = 'http://passport.tianya.cn/login';
		$postpage = makeRequest($url, 
								"POST" , 
								$postvalues, 
								true, 
								ROOT_PATH."/baidu/cookie/tianya_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/tianya_login_cookie.txt",
								$opt_arr
								);
		//printlog("data: $postpage", "tianya");
		preg_match_all('/document\.cookie=\'(.*?)=(.*?);/i',$postpage,$matches);
		preg_match_all('%type="text/javascript"(.*?)src="(.*?)"%i',$postpage,$urls);
		
		$count = count($matches[1]);
		$text = '';
		$i = 0 ;
		$timebegin = time();
		$exp = $timebegin + 2592000*1000;
		
		$timeexp = $timebegin +2592000;
		while($i < $count ){
			if($matches[1][$i] == 'time'){
				$text .= 'tianya.cn'."\t".'TRUE'."\t".'/'."\t".'FALSE'."\t".$exp."\t".$matches[1][$i]."\t".'st=1gES1F&ct='.$timebegin.'&et='.$timeexp."\n";
			}else{
				$text .= 'tianya.cn'."\t".'TRUE'."\t".'/'."\t".'FALSE'."\t".$exp."\t".$matches[1][$i]."\t".$matches[2][$i]."\n";
			}
			$i++;
		}
		file_put_contents(ROOT_PATH."/baidu/cookie/tianya_login_cookie.txt",$text);
		$opt_arr = array(
				CURLOPT_REFERER => "http://www.tianya.cn",  //referer	
			);
		foreach($urls[2] as $key=>$url){
			$page = makeRequest($url, 
									"GET" , 
									"", 
									true, 
									ROOT_PATH."/baidu/cookie/tianya_login_cookie.txt",
									ROOT_PATH."/baidu/cookie/tianya_login_cookie.txt",
									$opt_arr
									);
		}
		
		//自动发文章
		$url = "http://www.tianya.cn/blog/mypost";
		$opt_arr = array(
			CURLOPT_REFERER => "http://www.tianya.cn/blog/",  //referer	
		);
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/tianya_login_cookie.txt",
								$opt_arr
								);
		
		preg_match('/href="blogPost\.jsp\?blogId=(.*?)"\s*class="btn-post inputbtn ty-bluebtn">/i',$page,$uid);
		$writeurl =' http://www.tianya.cn/blog/blogPost.jsp?blogId='.$uid[1];
		
		$opt_arr = array(
			CURLOPT_REFERER => $writeurl,  //referer	
		);
		
		$postvalues = array(
				  'blogId'   => $uid[1],
				  'title'   => $title,
				  'content'   => $content,
				  'bHidden'   => 0,
				  'keyWord'   => '',
				  'categoryId'   => 0,
				  'setTop'   => 0,
				  );
		
		$posturl = 'http://blog.tianya.cn/qing/tyqing_post_submit.asp';
		$post = makeRequest($posturl, 
								"POST" , 
								$postvalues, 
								false, 
								ROOT_PATH."/baidu/cookie/tianya_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/tianya_login_cookie.txt",
								$opt_arr
								);
		var_dump($post);//string(56) "{"message":"发表成功!","data":{},"code":"0","success":1}"
	}
	// wuyicto post  just login  not post
	function wuyicto_post($username,$password,$catname=1,$title='默认', $content='默认的内容'){
		$opt_arr = array(
			CURLOPT_REFERER => "http://home.51cto.com/",  //referer	
		);
				
		$postvalues = array(
				  'email'          => $username,
				  'passwd'          => $password,
				  'reback'          => '',
				  'button.x'          => 57,
				  'button.y'          => 13,
				  );
		$url = 'http://home.51cto.com/index.php?s=/Index/doLogin';
		$postpage = makeRequest($url, 
								"POST" , 
								$postvalues, 
								true, 
								ROOT_PATH."/baidu/cookie/wuyicto_login_cookie.txt",
								ROOT_PATH."/baidu/cookie/wuyicto_login_cookie.txt",
								$opt_arr
								);
		preg_match_all('/src="(.*?)"/i',$postpage,$urls);
		
		foreach($urls[1] as $key=>$url){
			$page = makeRequest($url, 
									"GET" , 
									"", 
									true, 
									ROOT_PATH."/baidu/cookie/wuyicto_login_cookie.txt",
									ROOT_PATH."/baidu/cookie/wuyicto_login_cookie.txt",
									$opt_arr
									);
		}
		
		//自动发文章
		$url = "http://home.51cto.com/apps/blog/index.php?s=/Index/index/";
		$page = makeRequest($url, 
								"GET" , 
								"", 
								false, 
								"", 
								ROOT_PATH."/baidu/cookie/wuyicto_login_cookie.txt",
								$opt_arr
								);
		exit;
	}
?>